package com.itxzh.logindemo.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * Description
 *
 * @Author ldt
 * @Date 2022/5/24 16:49
 * @Version 1.0.0
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object handle(Exception exp) {
        log.error("error", exp);
        HashMap<String, Object> ret = new HashMap<>();
        ret.put("status", -1);
        ret.put("msg", "请求失败");
        ret.put("data", exp.getMessage());
        return ret;
    }
}
